/* $RCSFile: StringDataType.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/UI/DataTypes/StringDataType.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:29  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.IO;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

using AddonNice.Diagnostics;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.Configuration;

using Telerik.Web.UI;

namespace AddonNice.UI.DataTypes
{
    public enum TextMode { SingleLine, MultiLine, Password };
    
    
    /// <summary>
	/// StringDataType allows entering text in a textbox control
	/// </summary>
	public class StringDataType : BaseDataType
	{
        TextMode _StringTextMode    =   TextMode.SingleLine;
        int _nbLines                =   1;
        string _EmptyMessage         =   string.Empty;

        public TextMode StringTextMode
        {
            get
            { 
                return _StringTextMode;
            }
            set 
            {
                _StringTextMode    =   value;
            }
        }

        public int NbLines
        {
            get
            { 
                return _nbLines;
            }
            set 
            {
                _nbLines    =   value;
                if ( value > 1 )
                    _StringTextMode    =   TextMode.MultiLine;
            }
        }

        public string EmptyMessage
        {
            get
            { 
                return _EmptyMessage;
            }
            set 
            {
                _EmptyMessage    =   value;
            }
        }

        public StringDataType()
		{
			InnerDataType = PropertiesDataType.String;
		}

        public StringDataType(int nblines)
		{
			InnerDataType = PropertiesDataType.String;
            if (nblines > 1)
            {
                _StringTextMode = TextMode.MultiLine;
                _nbLines = nblines;
            }
		}

		public StringDataType(string value)
		{
			InnerDataType   = PropertiesDataType.String;
			Val             = value;
		}

		protected override void InitializeComponents()
		{
			if ( DataTypeTraceSwitch.Sw.TraceVerbose )
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]StringDataType InitializeComponents StringDataType UseRadControl: {0}, StringTextMode: {1}",_UsesRadControl,_StringTextMode),DataTypeTraceSwitch.Sw.Info);
            base.InitializeComponents();
            if (StringTextMode != TextMode.SingleLine)
            {
                if (UseRadControl)
                {
                    RadTextBox tx   =   (RadTextBox)innerControl;
                    tx.TextMode     =   (StringTextMode == TextMode.MultiLine) ? InputMode.MultiLine : InputMode.Password;
                    if ( tx.TextMode == InputMode.MultiLine )
                        tx.Rows     =   NbLines;
                    tx.EmptyMessage =   EmptyMessage;
                }
                else
                {
                    TextBox tx      =   (TextBox)innerControl;
                    tx.TextMode     =   (StringTextMode == TextMode.MultiLine) ? TextBoxMode.MultiLine : TextBoxMode.Password;
                    if ( tx.TextMode == TextBoxMode.MultiLine )
                        tx.Rows     =   NbLines;
                }
            }
		}

        public override string Description
		{
			get
			{
				return "String";
			}
		}
	}
}